package com.hxd.base;

import com.baomidou.mybatisplus.extension.service.IService;
import com.hxd.common.utils.GenericsUtils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ReflectUtil;

/**
 * IService接口扩展
 * @author zhoujw
 */
public interface BaseService<T, V> extends IService<T> {
	
	/**
	 * 获取泛型参数  实例化
	 * Type[] 0: Mapper
	 *        1: Entity
	 */
	default T newInstance() {
		return ReflectUtil.newInstance(GenericsUtils.getEntityClass(getClass()));
	}
	
	default boolean saveOrUpdate(V vo, String ... ignoreProperties) {
		final T entity = newInstance();
		BeanUtil.copyProperties(vo, entity, ignoreProperties);
		return saveOrUpdate(entity);
	}
	
}
